package com.xy.exam.service.serviceImpl;


import com.xy.exam.entity.Product;
import com.xy.exam.mapper.ProductMapper;
import com.xy.exam.service.ProductService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import static com.baomidou.mybatisplus.extension.toolkit.Db.*;

/**
 * @Author:徐莹
 * @Date:2025/04/13 11:21:25
 */
@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;

    @Cacheable(value = "product",key = "'product'+#id")
    @Override
    public Product findProductById(Integer id) {
        return productMapper.selectById(id);
    }



    @CachePut(value = "product",key = "'product'+#product.id")
    @Override
    public Product addProduct(Product product) {
        productMapper.insert(product);
        return product;
    }
    @CachePut(value = "product",key = "'product'+#product.id")
    @Override
    public Product updateProduct(Product product) {
        productMapper.updateById(product);
        return product;
    }
    @CacheEvict(value = "product",key = "'product'+#id")
    @Override
    public void deleteProduct(Integer id) {
        productMapper.deleteById(id);
    }
}
